package md.frolov.bible.indexes;

import java.io.File;

public class IXDictionary extends IX {
	public IXDictionary(File file) {
		super(file);
	}

	public long getOffset(String key){
		int ix = getIx(key, 0, keys.size()-1);
		return offsets.get(ix).longValue();
	}
	
	//bisection
	private int getIx(String key, int a, int b){
		if(b-a<=1) return a;
		int c = (b-a)>>1;
		int comp = keys.get(c).compareTo(key);
		if(comp == 0) return c;
		if(comp > 0 ) return getIx(key,a,c); //keys(c)>key
		return getIx(key,c,b); //keys(c)<key
	}

	@Override
	public String getType() {
		return this.getClass().getName();
	}
}
